package com.fu.consumer.controller;

import com.fu.core.common.JsonResult;
import com.fu.core.pojo.GoodsEsVo;
import com.fu.core.pojo.Type;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 付龙江
 * @date 2022/1/29 16:01
 */
@RestController
@RequestMapping("/type")
@CrossOrigin
@Api(tags = "前台分类相关接口")
public class TypeController {


    @PostMapping("/typeList")
    @ApiOperation(value = "分类列表")
    public Map<String,Object> typeList(){
        Map<Type, List<Type>> map = new HashMap<>();
        for (int i = 0; i < 4; i++) {
            Type type = new Type(i,"夏季水果",null,"/图片还没上传",null,"顶级类型");
            List<Type> typeList = new ArrayList<>();
            for (int j = 1; j <= 4; j++) {
                typeList.add(new Type(j,"夏季水果",null,"/图片还没上传",null,"顶级类型"));
            }
            map.put(type,typeList);
        }

        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("typeList",map);
        return jsonResult.getMap();
    }

    @PostMapping("/searchType")
    @ApiOperation(value = "通过type名称搜索商品")
    @ApiImplicitParam(name = "typeName", value = "类型名称",
            required = true, dataType = "String")
    public Map<String,Object> payMoney(String typeName){
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }
}
